void updateInput()
{
  updateMouse();
  updateKeys();
}

int[] getMousePos()
{
  int mousePos[] = {
    (int)mouseX, (int)mouseY
  };
  return mousePos;
}

void mousePressed()
{
  int mb = mouseButton;
  
  switch(mb)
  {
    case LEFT:
      mb = 0;
      break;
    case RIGHT:
      mb = 2;
      break;
    case CENTER:
      mb = 1;
      break;
  }
  
  if (mb < mouseDown.length && mouseDown[mb] == false &&
      frameOnWhichMouseWasLastPressed[mb] <= frameOnWhichMouseWasLastReleased[mb])
  {
    mouseDown[mb] = true;
    frameOnWhichMouseWasLastPressed[mb] = frameCount;
  }
}

void mouseReleased()
{
  int mb = mouseButton;
  
  switch(mb)
  {
    case LEFT:
      mb = 0;
      break;
    case RIGHT:
      mb = 2;
      break;
    case CENTER:
      mb = 1;
      break;
  }
  
  if (mb < mouseDown.length && mouseDown[mb] == true)
  {
    mouseDown[mb] = false;
    frameOnWhichMouseWasLastReleased[mb] = frameCount;
  }
}

void updateMouse()
{
  for (int i = 0; i < mouseJustPressed.length; i++)
  {
    // determine mouseJustPressed
    if (mouseJustPressed[i] == false &&
        frameOnWhichMouseWasLastPressed[i] > frameOnWhichMouseWasJustPressed[i])
    {
      mouseJustPressed[i] = true;
      frameOnWhichMouseWasJustPressed[i] = frameCount;
    }
    else
    {
      mouseJustPressed[i] = false;
    }
    
    // determin mouseJustReleased
    if (mouseJustReleased[i] == false &&
        frameOnWhichMouseWasLastReleased[i] > frameOnWhichMouseWasJustReleased[i])
    {
      mouseJustReleased[i] = true;
      frameOnWhichMouseWasJustReleased[i] = frameCount;
    }
    else
    {
      mouseJustReleased[i] = false;
    }
  }
}

void keyPressed()
{
  if (key < keyDown.length && keyDown[key] == false &&
      frameOnWhichKeyWasLastPressed[key] <= frameOnWhichKeyWasLastReleased[key])
  {
    keyDown[key] = true;
    frameOnWhichKeyWasLastPressed[key] = frameCount;
  }
}

void keyReleased()
{
  if (key < keyDown.length && keyDown[key] == true)
  {
    keyDown[key] = false;
    frameOnWhichKeyWasLastReleased[key] = frameCount;
  }
}

void updateKeys()
{
  for (int i = 0; i < keyJustPressed.length; i++)
  {
    // determine keyJustPressed
    if (keyJustPressed[i] == false &&
        frameOnWhichKeyWasLastPressed[i] > frameOnWhichKeyWasJustPressed[i])
    {
      keyJustPressed[i] = true;
      frameOnWhichKeyWasJustPressed[i] = frameCount;
    }
    else
    {
      keyJustPressed[i] = false;
    }
     
    // determine keyJustReleased 
    if (keyJustReleased[i] == false &&
        frameOnWhichKeyWasLastReleased[i] > frameOnWhichKeyWasJustReleased[i])
    {
      keyJustReleased[i] = true;
      frameOnWhichKeyWasJustReleased[i] = frameCount;
    }
    else
    {
      keyJustReleased[i] = false;
    }
  }
}
